from weibo import APIError, APIClient
from django.shortcuts import redirect
_APP_ID = "3007283299"
_APP_SECRET = "36d64c3b378852ce604e6123dcc4cc0e"

def _create_client():
    return APIClient(_APP_ID, _APP_SECRET, 'http://weiaa.sinaapp.com/callback')

def signin():
    client = _create_client()
    return redirect(client.get_authorize_url())
def callback(request):
	client = _create_client()
	access_code = request.GET.get('code')
	#print ("!!!!code = %s" % access_code)
	r = client.request_access_token(access_code)
	access_token = r.access_token
	expires_in = r.expires_in
	client.set_access_token(access_token, expires_in)